﻿using System;

namespace Transformable_Engine_v2.Engine.Transformable_Math.Geometry
{
    public class TE_Circle
    {
        /// <summary>
        /// Center coordinate of the circle
        /// </summary>
        public TE_Vector2 Center { get; set; }

        /// <summary>
        /// Radius of the circle
        /// </summary>
        public float Radius { get; set; }

        /// <summary>
        /// Diameter of the circle
        /// </summary>
        public float Diameter
        {
            get { return Radius * 2; }
            set
            {
                Radius = value/2;
            }
        }

        /// <summary>
        /// Creates a new instance of the circle class
        /// </summary>
        /// <param name="x">X component of the circle's center</param>
        /// <param name="y">Y component of the circle's center</param>
        /// <param name="radius">Radius of the circle</param>
        /// <param name="alignment">Alignment of the circle</param>
        public TE_Circle(float x, float y, float radius, TE_Rectangle.Alignment alignment = TE_Rectangle.Alignment.CenterMiddle) : this(new TE_Vector2(x, y), radius, alignment)
        {
            
        }

        /// <summary>
        /// Creates a new instance of the circle class
        /// </summary>
        /// <param name="center">Circle's center</param>
        /// <param name="radius">Radius of the circle</param>
        /// <param name="alignment">Alignment of the circle </param>
        public TE_Circle(TE_Vector2 center, float radius, TE_Rectangle.Alignment alignment = TE_Rectangle.Alignment.CenterMiddle)
        {
            switch (alignment) 
            {
                case TE_Rectangle.Alignment.TopLeft:
                    Center = center;
                    break;
                case TE_Rectangle.Alignment.TopMiddle:
                    Center = new TE_Vector2(center.X - radius, center.Y);
                    break;
                case TE_Rectangle.Alignment.TopRight:
                    Center = new TE_Vector2(center.X - radius * 2, center.Y);
                    break;
                case TE_Rectangle.Alignment.CenterLeft:
                    Center = new TE_Vector2(center.X, center.Y - radius);
                    break;
                case TE_Rectangle.Alignment.CenterMiddle:
                    Center = new TE_Vector2(center.X - radius, center.Y - radius);
                    break;
                case TE_Rectangle.Alignment.CenterRight:
                    Center = new TE_Vector2(center.X - radius * 2, center.Y - radius);
                    break;
                case TE_Rectangle.Alignment.BottomLeft:
                    Center = new TE_Vector2(center.X, center.Y - radius * 2);
                    break;
                case TE_Rectangle.Alignment.BottomMiddle:
                    Center = new TE_Vector2(center.X - radius, center.Y - radius * 2);
                    break;
                case TE_Rectangle.Alignment.BottomRight:
                    Center = new TE_Vector2(center.X - radius * 2, center.Y - radius * 2);
                    break;
                default:
                    throw new ArgumentOutOfRangeException("alignment");
            }

            
            Radius = radius;
        }
    }
}